package com.hongxun.project.assets.iPicture.service;

import java.util.List;
import java.util.UUID;

import com.hongxun.common.utils.bean.BeanUtils;
import com.hongxun.project.assets.iBoxes.domain.IBoxes;
import com.hongxun.project.assets.pBoxes.domain.PBoxes;
import com.hongxun.project.assets.pPicture.domain.PPicture;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hongxun.project.assets.iPicture.mapper.IPictureMapper;
import com.hongxun.project.assets.iPicture.domain.IPicture;
import com.hongxun.project.assets.iPicture.service.IIPictureService;
import com.hongxun.common.utils.text.Convert;

/**
 * 现场照片 服务层实现
 * 
 * @author hongxun
 * @date 2019-03-19
 */
@Service
public class IPictureServiceImpl implements IIPictureService 
{
	@Autowired
	private IPictureMapper iPictureMapper;

	/**
     * 查询现场照片信息
     * 
     * @param id 现场照片ID
     * @return 现场照片信息
     */
    @Override
	public IPicture selectIPictureById(String id)
	{
	    return iPictureMapper.selectIPictureById(id);
	}
	
	/**
     * 查询现场照片列表
     * 
     * @param iPicture 现场照片信息
     * @return 现场照片集合
     */
	@Override
	public List<IPicture> selectIPictureList(IPicture iPicture)
	{
	    return iPictureMapper.selectIPictureList(iPicture);
	}
	@Override
	public List<IPicture> selectIPictureListForPoint(IPicture iPicture)
	{
	    return iPictureMapper.selectIPictureListForPoint(iPicture);
	}
	
    /**
     * 新增现场照片
     * 
     * @param iPicture 现场照片信息
     * @return 结果
     */
	@Override
	public int insertIPicture(IPicture iPicture)
	{
		iPicture.setId(UUID.randomUUID().toString());
	    return iPictureMapper.insertIPicture(iPicture);
	}
	
	/**
     * 修改现场照片
     * 
     * @param iPicture 现场照片信息
     * @return 结果
     */
	@Override
	public int updateIPicture(IPicture iPicture)
	{
	    return iPictureMapper.updateIPicture(iPicture);
	}

	/**
     * 删除现场照片对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteIPictureByIds(String ids)
	{
		return iPictureMapper.deleteIPictureByIds(Convert.toStrArray(ids));
	}


	@Override
	public List<IPicture> selectListOrderByType(IPicture iPicture) {
		return iPictureMapper.selectListOrderByType(iPicture);
	}


	public void file(List<PPicture> pPicture) {
		for (PPicture p : pPicture) {
			if (p.getDatastate().equals("删除")) {
				deleteIPictureByIds(p.getId());
			} else {
				IPicture i = new IPicture();
				BeanUtils.copyBeanProp(i, p);
				if (selectIPictureById(p.getId()) != null) {
					updateIPicture(i);
				} else {
					iPictureMapper.insertIPicture(i);
				}
			}
		}
	}
}
